package cn.bopomo.dealer.base.action.ajax;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONObject;

import cn.bopomo.dealer.base.action.BaseAction;
import cn.bopomo.dealer.base.common.ServiceConfig;
import cn.bopomo.dealer.base.service.IOperatorService;
import cn.bopomo.dealer.base.util.ResultCode;
import cn.bopomo.dealer.base.vo.AuthorizeList;

public class DeleteAuthorizeAjax extends BaseAction {

	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//AJAX返回设置
		response.setContentType("text/html;charset=UTF-8");
		response.setHeader("Cache-control","no-cache");
		
		StringBuffer result = new StringBuffer();
		String op_result = ResultCode.OP_FAILED;;
		
		//获取参数
		Integer aid = new Integer(request.getParameter("aid"));
		//获取Service
		IOperatorService os = (IOperatorService)this.findService(ServiceConfig.OPERATOR_SERVICE);
		//获取"权限"实例
		AuthorizeList authorize = os.getAuthorize(aid);
		if (authorize != null){
			//删除"权限"实例
			op_result = os.deleteAuthorize(authorize);
		}
		//组合返回信息
		result.append(op_result).append("||").append(this.getCodeDescription(op_result,request.getSession().getServletContext().getResource(this.codeDescXMLPath).getPath()));
		log.info(authorize.getAid() + ":" + authorize.getAuthorizeName() + "  " + result);
		//返回 
		response.getWriter().write(result.toString());
		return null;
	}

}
